import { Page } from '@/base/Page';
import { Family } from '@/base/model/Family';
import { isEmpty } from '@/base/util/Strings';
import {getFamilyList} from '@/base/api/FamilyApi';

import { RoleRelationship } from '@/base/model/RoleRelationship';
import {getRoleRelationshipList,deleteRoleRelationship} from '@/base/api/RoleRelationshipApi';

class Form {
  id = 0;
  masterId = 0;
  salveId = 0;
  created = '';
  updated = '';
  agentName = '';
}

export class ListBloc {
  form = new Form();

  paged: Page<RoleRelationship> = new Page<RoleRelationship>([], 0, 1, 15, 0, []);
  loading = false;

  load(pageIndex: number, pageSize: number,masterId: number,agentName: string) {
    this.loading = true;
    return getRoleRelationshipList({
      pageIndex: pageIndex,
      pageSize: pageSize,
      masterId: masterId,
      agentName: agentName
    }).then((res) => {
      this.paged = res.data;
    }).finally(() => {
      this.loading = false;
    });
  }

  removeItem(dateItem: RoleRelationship) {
    this.loading = true;
    return deleteRoleRelationship(dateItem.id)
      .finally(() => {
        this.loading = false;
      });
  }

  reset() {
    this.form.id = 0;
    this.form.salveId = 0;
    this.form.created = '';
    this.form.updated = '';
    this.form.agentName = '';
    this.paged.pageIndex = 1;
    this.paged.pageSize = 15;
    this.load(this.paged.pageIndex, this.paged.pageSize,this.form.masterId,this.form.agentName);
  }

}
